package com.uniview.butterknifedemo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by Lenovo on 2017/4/22.
 */

public class ViewPagerFragment extends Fragment {

    private int status;

    @BindView(R.id.text)
    TextView textView;

    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    @BindArray(R.array.array)
    String[] arrays;

    @BindArray(R.array.array2)
    String[] arrays2;

    private Unbinder unbinder;

    private DisplayAdapter displayAdapter;
    private LinearLayoutManager linearLayoutManager;

    public static ViewPagerFragment newInstance(int status) {
        ViewPagerFragment viewPagerFragment = new ViewPagerFragment();

        Bundle args = new Bundle();
        args.putInt("status", status);
        viewPagerFragment.setArguments(args);

        return viewPagerFragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        status = getArguments() != null ? getArguments().getInt("status") : 1;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        return super.onCreateView(inflater, container, savedInstanceState);
        View v = inflater.inflate(R.layout.fragment_view, container, false);
        unbinder = ButterKnife.bind(this, v);

        textView.setText("statu: " + status);

        linearLayoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(linearLayoutManager);

        if (status == 0 || status == 2) {
            displayAdapter = new DisplayAdapter(getActivity(), java.util.Arrays.asList(arrays));
        } else {
            displayAdapter = new DisplayAdapter(getActivity(), java.util.Arrays.asList(arrays2));
        }
        recyclerView.setAdapter(displayAdapter);
        return v;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
